<template>
  <div class="login-wrapper">
    <div class="login-container">
      <div class="logo-container">
        <img src="../assets/logo.png" alt="Logo" class="logo">
      </div>
      <form @submit.prevent="handleLogin">
        <div class="form-group">
          <div class="input-icon">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path fill="currentColor" d="M12 4a4 4 0 014 4 4 4 0 01-4 4 4 4 0 01-4-4 4 4 0 014-4m0 10c4.42 0 8 1.79 8 4v2H4v-2c0-2.21 3.58-4 8-4z"/>
            </svg>
          </div>
          <input
            type="text"
            id="username"
            v-model="username"
            placeholder="请输入用户名"
            required
          />
        </div>
        <div class="form-group">
          <div class="input-icon">
            <svg viewBox="0 0 24 24" width="24" height="24">
              <path fill="currentColor" d="M12 17a2 2 0 01-2-2c0-1.11.89-2 2-2a2 2 0 012 2 2 2 0 01-2 2m6-9a2 2 0 012 2v10a2 2 0 01-2 2H6a2 2 0 01-2-2V10a2 2 0 012-2h1V6a5 5 0 015-5 5 5 0 015 5v2h1m-6-2a3 3 0 00-3 3v2h6V6a3 3 0 00-3-3z"/>
            </svg>
          </div>
          <input
            type="password"
            id="password"
            v-model="password"
            placeholder="请输入密码"
            required
          />
        </div>
        <div v-if="errorMessage" class="error-message">
          {{ errorMessage }}
        </div>
        <button type="submit" :disabled="isLoading">
          <span v-if="!isLoading">登录</span>
          <span v-else class="loading-spinner"></span>
        </button>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      errorMessage: '',
      isLoading: false
    };
  },
  methods: {
    async handleLogin() {
      this.isLoading = true;
      this.errorMessage = '';
      
      try {
        // 模拟登录请求
        await new Promise(resolve => setTimeout(resolve, 1000));
        
        if (this.username === 'admin' && this.password === 'password') {
          localStorage.setItem('isAuthenticated', 'true');
          this.$router.push('/dashboard');
        } else {
          this.errorMessage = '用户名或密码错误';
        }
      } catch (error) {
        this.errorMessage = '登录失败，请稍后重试';
      } finally {
        this.isLoading = false;
      }
    }
  }
};
</script>

<style scoped>
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.login-container {
  max-width: 400px;
  width: 100%;
  padding: 2.5rem;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  animation: fadeIn 0.5s ease;
}

.logo-container {
  text-align: center;
  margin-bottom: 2rem;
  animation: float 3s ease-in-out infinite;
}

.logo {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

.form-group {
  position: relative;
  margin-bottom: 1.5rem;
}

.input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: #666;
  z-index: 1;
}

input {
  width: 100%;
  padding: 0.8rem 0.8rem 0.8rem 2.5rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s ease;
  box-sizing: border-box;
  background-color: rgba(255, 255, 255, 0.9);
}

input:hover {
  border-color: #42b983;
}

input:focus {
  border-color: #42b983;
  box-shadow: 0 0 0 3px rgba(66, 185, 131, 0.2);
  outline: none;
}

.error-message {
  color: #dc3545;
  font-size: 0.9rem;
  margin: -0.5rem 0 1rem;
  text-align: center;
}

button {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, #42b983, #33a06f);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 1rem;
  position: relative;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(66, 185, 131, 0.4);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

.loading-spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 480px) {
  .login-container {
    margin: 1rem;
    padding: 1.5rem;
  }
  
  .logo {
    width: 80px;
    height: 80px;
  }
}
</style>
